#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct Edge
{
    int to, cost;
};
vector<Edge> G[100001];
int dist[100001];
bool visit[100001];
void dijkstra(int s)
{
    fill(dist, dist + 100000, 1 << 30);
    dist[s] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, s));
    while (!pq.empty())
    {
        pair<int, int> P = pq.top();
        pq.pop();
        if (dist[P.second] < P.first)
            continue;
        else
        {
            for (int i = 0; i < G[P.second].size(); i++)
            {
                if (dist[G[P.second][i].to] > dist[P.second] + G[P.second][i].cost)
                {
                    dist[G[P.second][i].to] = dist[P.second] + G[P.second][i].cost;
                    pq.push(make_pair(dist[G[P.second][i].to], G[P.second][i].to));
                }
            }
        }
    }
}
int main()
{
    int N, M, S, K;
    int temp_from, temp_to, temp_cost;
    Edge temp_edge1, temp_edge2;
    cin >> N >> M >> S;
    for (int i = 0; i < M; i++)
    {
        cin >> temp_from >> temp_to >> temp_cost;
        temp_edge1.to = temp_to;
        temp_edge1.cost = temp_cost;
        temp_edge2.to = temp_from;
        temp_edge2.cost = temp_cost;
        G[temp_from].push_back(temp_edge1);
        G[temp_to].push_back(temp_edge2);
    }
    dijkstra(S);
    cin >> K;
   
    int ans = 0;
    if(K==0)    ans++;
    for (int i = 1; i <= N; i++)
    {
        int size = G[i].size();
        for (int j = 0; j < size; j++)
        {
            if (G[i][j].to < i)
                continue;
            if (2 * K > G[i][j].cost + dist[i] + dist[G[i][j].to])
                continue;
            else if (2 * K == G[i][j].cost + dist[i] + dist[G[i][j].to])
            {
                ans++;
                if(dist[G[i][j].to]==K&&visit[G[i][j].to]==true)    ans--;
                visit[G[i][j].to]=true;
                continue;
            }
            else
            {
                if (dist[i] < K)
                    ans++;
                if (dist[G[i][j].to] < K)
                    ans++;
            }
        }
    }
    cout << ans;
    cin >> N;
}